<template>
	<div>
		<el-row :gutter="10">
			<el-col :span="5">
				<el-input v-model="search.name" placeholder="请输入要查询的用户名"></el-input>
			</el-col>
			<el-col :span="19">
				<el-button type="primary" icon="el-icon-search" plain @click="searchData()">查询</el-button>
				<el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">增加</el-button>
			</el-col>
		</el-row>
		<el-table :data="result.tableData" style="width: 100%" @selection-change="handleSelectionChange">
			<el-table-column type="selection">
			</el-table-column>
			<el-table-column prop="objectId" label="序号" width="120">
			</el-table-column>
			<el-table-column prop="name" label="管家姓名" width="120">
			</el-table-column>
			<el-table-column prop="roleName" label="角色名称" width="120">
			</el-table-column>
			<el-table-column prop="managerTel" label="联系电话" width="120">
			</el-table-column>
			<el-table-column prop="serviceFloor" label="服务楼层" width="120">
			</el-table-column>
			</el-table-column>
			<el-table-column prop="note" label="备注" width="120">
			</el-table-column>
			</el-table-column>
			<el-table-column prop="operationTime" label="操作时间" width="120">
			</el-table-column>
			<el-table-column label="操作" width="220px">
				<template slot-scope="scope">
					<template>
						<el-button size="mini" @click="handleEdit(scope.row.objectId)">编辑</el-button>
						<el-button size="mini" type="danger" @click="handleDelete(scope.row.objectId)">删除</el-button>
					</template>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination style="margin-top:20px;" background layout="prev, pager, next" :page-count="result.pages"
			:current-page.sync="query.current" :page-size="query.size" @current-change="getData()">
		</el-pagination>
		<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="500px">
			<ServiceObjectEdit v-if="show" :show.sync="show" @getData="getData()" :editid="editid">
			</ServiceObjectEdit>
		</el-dialog>
	</div>
</template>

<script>
	import ServiceObjectEdit from '@/views/service_object/edit'
	export default {
		name: 'ServiceObject',
		data() {
			return {
				search: {
					name: ''
				},
				query: {
					name: '',
					current: 1,
					size: 2
				},
				result: {
					tableData: [],
					pages: 0
				},
				show: false,
				editid: null,
				selectedrow: [],
				title: ''
			}
		},
		components: {
			ServiceObjectEdit,
		},
		created() {
			this.getData()
		},
		methods: {
			getData() {
				this.axios.get('/serviceObject/list', response => {
					this.result.tableData = response.obj.records
					this.result.pages = response.obj.pages
				}, this.query)
			},
			searchData() {
				this.query.name = this.search.name
				this.query.current = 1
				this.getData()
			},
			handleEdit(objectId) {
				this.title = '修改服务对象'
				this.editid = objectId
				this.show = true
			},
			add() {
				this.title = '设置服务对象'
				this.editid = null
				this.show = true
			},
			handleDelete(objectId) {
				this.axios.del('/serviceObject/delete/' + objectId, response => {
					this.getData()
				}, {
					objectId: objectId
				})
			},
			handleSelectionChange(val) {
				// val参数为所有选中行的数据
				this.selectedrow = val
			}
			// batchdel() {
			//   if(this.selectedrow.length === 0) {
			//     this.$message('没有任何被选中的数据');
			//   } else {
			//     const ids = []
			// 	console.log(this.selectedrow.length)
			//     for(let i = 0; i < this.selectedrow.length; i++) {
			//       ids.push(this.selectedrow[i].fileId)
			//     }
			//     this.axios.get('/healthFile/batchdel',response => {
			//       this.getData()
			//     },{ 
			// 		id: ids.join(",") 
			// 	})
			//   }
		}

	}
</script>
<style scoped>
</style>
